package com.example.chapter03;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import com.example.chapter03.util.DateUtil;

public class ButtonLongClickAcivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_button_long_click_acivity);
        TextView tv_results = findViewById(R.id.tv_results);
        Button btn_click_long = findViewById(R.id.btn_click_long);
        TextView tv_result = findViewById(R.id.tv_result);
        Button btn_click_long2 = findViewById(R.id.btn_click_long2);
        btn_click_long.setOnLongClickListener(view -> {
            String desc = String.format("%s 您长摁了按钮：    %s",
                    DateUtil.getNowTime(),((Button) view).getText());
            tv_results.setText(desc);
            return true;
        });
        btn_click_long2.setOnLongClickListener(view -> {
            String desc = String.format("%s 您长摁了按钮：    %s",
                    DateUtil.getNowTime(),((Button) view).getText());
            tv_result.setText(desc);
            return true;
        });
    }
}